package com.data.modules.online.config.SQLite;

import com.data.modules.online.cgform.extend.ExtendJsonKey;
import com.data.modules.online.cgform.util.OnlFormShowType;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.function.SQLFunctionTemplate;
import org.hibernate.dialect.function.StandardSQLFunction;
import org.hibernate.dialect.function.VarArgsSQLFunction;
import org.hibernate.type.StandardBasicTypes;

public final class SQLiteDialect extends Dialect {
    public SQLiteDialect() {
        registerColumnType(0, "null");
        registerColumnType(-7, "integer");
        registerColumnType(-6, "integer");
        registerColumnType(5, "integer");
        registerColumnType(4, "integer");
        registerColumnType(-5, "integer");
        registerColumnType(16, "integer");
        registerColumnType(7, "real");
        registerColumnType(8, "real");
        registerColumnType(6, "real");
        registerColumnType(2, "numeric");
        registerColumnType(3, "numeric");
        registerColumnType(1, ExtendJsonKey.f91e);
        registerColumnType(12, ExtendJsonKey.f91e);
        registerColumnType(2005, ExtendJsonKey.f91e);
        registerColumnType(-1, ExtendJsonKey.f91e);
        registerColumnType(2004, "blob");
        registerColumnType(2005, "clob");
        registerColumnType(91, OnlFormShowType.f320d);
        registerColumnType(93, "datetime");
        registerFunction("concat", new VarArgsSQLFunction(StandardBasicTypes.STRING, "", "||", ""));
        registerFunction("mod", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "?1 % ?2"));
        registerFunction("substr", new StandardSQLFunction("substr", StandardBasicTypes.STRING));
        registerFunction("substring", new StandardSQLFunction("substr", StandardBasicTypes.STRING));
    }

    public boolean mo1187a() {
        return true;
    }

    public boolean mo1188b() {
        return false;
    }

    public String getIdentityColumnString() {
        return "integer";
    }

    public String getIdentitySelectString() {
        return "select last_insert_rowid()";
    }

    public boolean supportsLimit() {
        return true;
    }


    public String getLimitString(String query, boolean hasOffset) {
        return new StringBuffer(query.length() + 20).append(query).append(hasOffset ? " limit ? offset ?" : " limit ?").toString();
    }

    public boolean mo1189c() {
        return true;
    }

    public String getCreateTemporaryTableString() {
        return "create temporary table if not exists";
    }

    public boolean mo1190d() {
        return false;
    }

    public boolean supportsCurrentTimestampSelection() {
        return true;
    }

    public boolean isCurrentTimestampSelectStringCallable() {
        return false;
    }

    public String getCurrentTimestampSelectString() {
        return "select current_timestamp";
    }

    public boolean supportsUnionAll() {
        return true;
    }

    public boolean hasAlterTable() {
        return false;
    }

    public boolean dropConstraints() {
        return false;
    }

    public String getAddColumnString() {
        return "add column";
    }

    public String getForUpdateString() {
        return "";
    }

    public boolean supportsOuterJoinForUpdate() {
        return false;
    }

    public String getDropForeignKeyString() {
        throw new UnsupportedOperationException("No drop foreign key syntax supported by SQLiteDialect");
    }

    public String getAddForeignKeyConstraintString(String constraintName, String[] foreignKey, String referencedTable, String[] primaryKey, boolean referencesPrimaryKey) {
        throw new UnsupportedOperationException("No add foreign key syntax supported by SQLiteDialect");
    }

    public String getAddPrimaryKeyConstraintString(String constraintName) {
        throw new UnsupportedOperationException("No add primary key syntax supported by SQLiteDialect");
    }

    public boolean supportsIfExistsBeforeTableName() {
        return true;
    }

    public boolean supportsCascadeDelete() {
        return false;
    }
}
